package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.entity.CoreKnowledgeBase;
import com.corechina.apex_osswords.service.ICoreKnowledgeBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 知识库 前端控制器
 * </p>
 *
 * @author fyh
 * @since 2023-02-03
 */
@Api(tags = "知识库")
@RestController
@RequestMapping("/core/knowledgeBase")
public class CoreKnowledgeBaseController {

    @Autowired
    private ICoreKnowledgeBaseService iCoreKnowledgeBaseService;

    @SysLog("新增知识库")
    @ApiOperation("新增知识库")
    @PostMapping("/add")
    public Response add(@RequestBody CoreKnowledgeBase coreKnowledgeBase) {
        return iCoreKnowledgeBaseService.add(coreKnowledgeBase);
    }

    @SysLog("删除知识库")
    @ApiOperation("删除知识库")
    @DeleteMapping("/del")
    public Response del(Integer id) {
        if (iCoreKnowledgeBaseService.removeById(id)) {
            return Response.ok();
        }
        return Response.error();
    }

    @SysLog("编辑知识库")
    @ApiOperation("编辑知识库")
    @PutMapping("/update")
    public Response update(@RequestBody CoreKnowledgeBase coreKnowledgeBase) {
        coreKnowledgeBase.setEnterpriseId(null);
        coreKnowledgeBase.setCreateTime(null);
        coreKnowledgeBase.setCreator(null);
        if (iCoreKnowledgeBaseService.updateById(coreKnowledgeBase)) {
            return Response.ok();
        }
        return Response.error();
    }

    @ApiOperation("列表")
    @GetMapping("/getList")
    public Response getList(Integer type, String name, Integer pageIndex, Integer pageSize) {
        return iCoreKnowledgeBaseService.getList(type, name, pageIndex, pageSize);
    }

    @ApiOperation("详情")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return iCoreKnowledgeBaseService.getOne(id);
    }

    @ApiOperation("微信获取表")
    @GetMapping("/getListForWeiXin")
    public Response getListForWeiXin(Integer type, Integer pageIndex, Integer pageSize) {
        return iCoreKnowledgeBaseService.getListForWeiXin(type, pageIndex, pageSize);
    }

    @ApiOperation("微信详情")
    @GetMapping("/getOneForWeiXin")
    public Response getOneForWeiXin(Integer id) {
        return iCoreKnowledgeBaseService.getOneForWeiXin(id);
    }

}

